
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/functions/combinatorial.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:28:19 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Combinatorial &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
    <script src="../../_static/jquery.js"></script>
    <script src="../../_static/underscore.js"></script>
    <script src="../../_static/doctools.js"></script>
    <script src="../../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../../live.sympy.org/static/live-sphinx.js"></script>
    <script async="async" src="../../../../cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest8331.js?config=TeX-AMS_HTML-full"></script>
    <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]]}})</script>
    
    <link rel="shortcut icon" href="../../_static/sympy-notailtext-favicon.ico"/>
    <link href="combinatorial.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="Special" href="special.html" />
    <link rel="prev" title="Elementary" href="elementary.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="special.html" title="Special"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="elementary.html" title="Elementary"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" accesskey="U">Functions</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Combinatorial</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="combinatorial">
<h1>Combinatorial<a class="headerlink" href="#combinatorial" title="Permalink to this headline">¶</a></h1>
<p>This module implements various combinatorial functions.</p>
<section id="bell">
<h2>bell<a class="headerlink" href="#bell" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.functions.combinatorial.numbers.bell">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.functions.combinatorial.numbers.</span></span><span class="sig-name descname"><span class="pre">bell</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k_sym</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">symbols</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/functions/combinatorial/numbers.py#L534-L677"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.functions.combinatorial.numbers.bell" title="Permalink to this definition">¶</a></dt>
<dd><p>Bell numbers / Bell polynomials</p>
<p>The Bell numbers satisfy <span class="math notranslate nohighlight">\(B_0 = 1\)</span> and</p>
<div class="math notranslate nohighlight">
\[B_n = \sum_{k=0}^{n-1} \binom{n-1}{k} B_k.\]</div>
<p>They are also given by:</p>
<div class="math notranslate nohighlight">
\[B_n = \frac{1}{e} \sum_{k=0}^{\infty} \frac{k^n}{k!}.\]</div>
<p>The Bell polynomials are given by <span class="math notranslate nohighlight">\(B_0(x) = 1\)</span> and</p>
<div class="math notranslate nohighlight">
\[B_n(x) = x \sum_{k=1}^{n-1} \binom{n-1}{k-1} B_{k-1}(x).\]</div>
<p>The second kind of Bell polynomials (are sometimes called “partial” Bell
polynomials or incomplete Bell polynomials) are defined as</p>
<div class="math notranslate nohighlight">
\[B_{n,k}(x_1, x_2,\dotsc x_{n-k+1}) =
\sum_{j_1+j_2+j_2+\dotsb=k \atop j_1+2j_2+3j_2+\dotsb=n}
    \frac{n!}{j_1!j_2!\dotsb j_{n-k+1}!}
    \left(\frac{x_1}{1!} \right)^{j_1}
    \left(\frac{x_2}{2!} \right)^{j_2} \dotsb
    \left(\frac{x_{n-k+1}}{(n-k+1)!} \right) ^{j_{n-k+1}}.\]</div>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">bell(n)</span></code> gives the <span class="math notranslate nohighlight">\(n^{th}\)</span> Bell number, <span class="math notranslate nohighlight">\(B_n\)</span>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">bell(n,</span> <span class="pre">x)</span></code> gives the <span class="math notranslate nohighlight">\(n^{th}\)</span> Bell polynomial, <span class="math notranslate nohighlight">\(B_n(x)\)</span>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">bell(n,</span> <span class="pre">k,</span> <span class="pre">(x1,</span> <span class="pre">x2,</span> <span class="pre">...))</span></code> gives Bell polynomials of the second kind,
<span class="math notranslate nohighlight">\(B_{n,k}(x_1, x_2, \dotsc, x_{n-k+1})\)</span>.</p></li>
</ul>
<p class="rubric">Notes</p>
<p>Not to be confused with Bernoulli numbers and Bernoulli polynomials,
which use the same notation.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">bell</span><span class="p">,</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">symbols</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">bell</span><span class="p">(</span><span class="n">n</span><span class="p">)</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">11</span><span class="p">)]</span>
<span class="go">[1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bell</span><span class="p">(</span><span class="mi">30</span><span class="p">)</span>
<span class="go">846749014511809332450147</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bell</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;t&#39;</span><span class="p">))</span>
<span class="go">t**4 + 6*t**3 + 7*t**2 + t</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bell</span><span class="p">(</span><span class="mi">6</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x:6&#39;</span><span class="p">)[</span><span class="mi">1</span><span class="p">:])</span>
<span class="go">6*x1*x5 + 15*x2*x4 + 10*x3**2</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.functions.combinatorial.numbers.bernoulli" title="sympy.functions.combinatorial.numbers.bernoulli"><code class="xref py py-obj docutils literal notranslate"><span class="pre">bernoulli</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.catalan" title="sympy.functions.combinatorial.numbers.catalan"><code class="xref py py-obj docutils literal notranslate"><span class="pre">catalan</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.euler" title="sympy.functions.combinatorial.numbers.euler"><code class="xref py py-obj docutils literal notranslate"><span class="pre">euler</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.fibonacci" title="sympy.functions.combinatorial.numbers.fibonacci"><code class="xref py py-obj docutils literal notranslate"><span class="pre">fibonacci</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.harmonic" title="sympy.functions.combinatorial.numbers.harmonic"><code class="xref py py-obj docutils literal notranslate"><span class="pre">harmonic</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.lucas" title="sympy.functions.combinatorial.numbers.lucas"><code class="xref py py-obj docutils literal notranslate"><span class="pre">lucas</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.genocchi" title="sympy.functions.combinatorial.numbers.genocchi"><code class="xref py py-obj docutils literal notranslate"><span class="pre">genocchi</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.partition" title="sympy.functions.combinatorial.numbers.partition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">partition</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.tribonacci" title="sympy.functions.combinatorial.numbers.tribonacci"><code class="xref py py-obj docutils literal notranslate"><span class="pre">tribonacci</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r183"><span class="brackets"><a class="fn-backref" href="#id1">R183</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Bell_number">https://en.wikipedia.org/wiki/Bell_number</a></p>
</dd>
<dt class="label" id="r184"><span class="brackets"><a class="fn-backref" href="#id2">R184</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/BellNumber.html">http://mathworld.wolfram.com/BellNumber.html</a></p>
</dd>
<dt class="label" id="r185"><span class="brackets"><a class="fn-backref" href="#id3">R185</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/BellPolynomial.html">http://mathworld.wolfram.com/BellPolynomial.html</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="bernoulli">
<h2>bernoulli<a class="headerlink" href="#bernoulli" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.functions.combinatorial.numbers.bernoulli">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.functions.combinatorial.numbers.</span></span><span class="sig-name descname"><span class="pre">bernoulli</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sym</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/functions/combinatorial/numbers.py#L393-L524"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.functions.combinatorial.numbers.bernoulli" title="Permalink to this definition">¶</a></dt>
<dd><p>Bernoulli numbers / Bernoulli polynomials</p>
<p>The Bernoulli numbers are a sequence of rational numbers
defined by <span class="math notranslate nohighlight">\(B_0 = 1\)</span> and the recursive relation (<span class="math notranslate nohighlight">\(n &gt; 0\)</span>):</p>
<div class="math notranslate nohighlight">
\[0 = \sum_{k=0}^n \binom{n+1}{k} B_k\]</div>
<p>They are also commonly defined by their exponential generating
function, which is <span class="math notranslate nohighlight">\(\frac{x}{e^x - 1}\)</span>. For odd indices &gt; 1, the
Bernoulli numbers are zero.</p>
<p>The Bernoulli polynomials satisfy the analogous formula:</p>
<div class="math notranslate nohighlight">
\[B_n(x) = \sum_{k=0}^n \binom{n}{k} B_k x^{n-k}\]</div>
<p>Bernoulli numbers and Bernoulli polynomials are related as
<span class="math notranslate nohighlight">\(B_n(0) = B_n\)</span>.</p>
<p>We compute Bernoulli numbers using Ramanujan’s formula:</p>
<div class="math notranslate nohighlight">
\[B_n = \frac{A(n) - S(n)}{\binom{n+3}{n}}\]</div>
<p>where:</p>
<div class="math notranslate nohighlight">
\[\begin{split}A(n) = \begin{cases} \frac{n+3}{3} &amp;
n \equiv 0\ \text{or}\ 2 \pmod{6} \\
-\frac{n+3}{6} &amp; n \equiv 4 \pmod{6} \end{cases}\end{split}\]</div>
<p>and:</p>
<div class="math notranslate nohighlight">
\[S(n) = \sum_{k=1}^{[n/6]} \binom{n+3}{n-6k} B_{n-6k}\]</div>
<p>This formula is similar to the sum given in the definition, but
cuts 2/3 of the terms. For Bernoulli polynomials, we use the
formula in the definition.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">bernoulli(n)</span></code> gives the nth Bernoulli number, <span class="math notranslate nohighlight">\(B_n\)</span></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">bernoulli(n,</span> <span class="pre">x)</span></code> gives the nth Bernoulli polynomial in <span class="math notranslate nohighlight">\(x\)</span>, <span class="math notranslate nohighlight">\(B_n(x)\)</span></p></li>
</ul>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">bernoulli</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">bernoulli</span><span class="p">(</span><span class="n">n</span><span class="p">)</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">11</span><span class="p">)]</span>
<span class="go">[1, -1/2, 1/6, 0, -1/30, 0, 1/42, 0, -1/30, 0, 5/66]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bernoulli</span><span class="p">(</span><span class="mi">1000001</span><span class="p">)</span>
<span class="go">0</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.functions.combinatorial.numbers.bell" title="sympy.functions.combinatorial.numbers.bell"><code class="xref py py-obj docutils literal notranslate"><span class="pre">bell</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.catalan" title="sympy.functions.combinatorial.numbers.catalan"><code class="xref py py-obj docutils literal notranslate"><span class="pre">catalan</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.euler" title="sympy.functions.combinatorial.numbers.euler"><code class="xref py py-obj docutils literal notranslate"><span class="pre">euler</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.fibonacci" title="sympy.functions.combinatorial.numbers.fibonacci"><code class="xref py py-obj docutils literal notranslate"><span class="pre">fibonacci</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.harmonic" title="sympy.functions.combinatorial.numbers.harmonic"><code class="xref py py-obj docutils literal notranslate"><span class="pre">harmonic</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.lucas" title="sympy.functions.combinatorial.numbers.lucas"><code class="xref py py-obj docutils literal notranslate"><span class="pre">lucas</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.genocchi" title="sympy.functions.combinatorial.numbers.genocchi"><code class="xref py py-obj docutils literal notranslate"><span class="pre">genocchi</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.partition" title="sympy.functions.combinatorial.numbers.partition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">partition</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.tribonacci" title="sympy.functions.combinatorial.numbers.tribonacci"><code class="xref py py-obj docutils literal notranslate"><span class="pre">tribonacci</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r186"><span class="brackets"><a class="fn-backref" href="#id4">R186</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Bernoulli_number">https://en.wikipedia.org/wiki/Bernoulli_number</a></p>
</dd>
<dt class="label" id="r187"><span class="brackets"><a class="fn-backref" href="#id5">R187</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Bernoulli_polynomial">https://en.wikipedia.org/wiki/Bernoulli_polynomial</a></p>
</dd>
<dt class="label" id="r188"><span class="brackets"><a class="fn-backref" href="#id6">R188</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/BernoulliNumber.html">http://mathworld.wolfram.com/BernoulliNumber.html</a></p>
</dd>
<dt class="label" id="r189"><span class="brackets"><a class="fn-backref" href="#id7">R189</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/BernoulliPolynomial.html">http://mathworld.wolfram.com/BernoulliPolynomial.html</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="binomial">
<h2>binomial<a class="headerlink" href="#binomial" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.functions.combinatorial.factorials.binomial">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.functions.combinatorial.factorials.</span></span><span class="sig-name descname"><span class="pre">binomial</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/functions/combinatorial/factorials.py#L819-L1105"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.functions.combinatorial.factorials.binomial" title="Permalink to this definition">¶</a></dt>
<dd><p>Implementation of the binomial coefficient. It can be defined
in two ways depending on its desired interpretation:</p>
<div class="math notranslate nohighlight">
\[\binom{n}{k} = \frac{n!}{k!(n-k)!}\ \text{or}\
\binom{n}{k} = \frac{ff(n, k)}{k!}\]</div>
<p>First, in a strict combinatorial sense it defines the
number of ways we can choose <span class="math notranslate nohighlight">\(k\)</span> elements from a set of
<span class="math notranslate nohighlight">\(n\)</span> elements. In this case both arguments are nonnegative
integers and binomial is computed using an efficient
algorithm based on prime factorization.</p>
<p>The other definition is generalization for arbitrary <span class="math notranslate nohighlight">\(n\)</span>,
however <span class="math notranslate nohighlight">\(k\)</span> must also be nonnegative. This case is very
useful when evaluating summations.</p>
<p>For the sake of convenience for negative integer <span class="math notranslate nohighlight">\(k\)</span> this function
will return zero no matter what valued is the other argument.</p>
<p>To expand the binomial when <span class="math notranslate nohighlight">\(n\)</span> is a symbol, use either
<code class="docutils literal notranslate"><span class="pre">expand_func()</span></code> or <code class="docutils literal notranslate"><span class="pre">expand(func=True)</span></code>. The former will keep
the polynomial in factored form while the latter will expand the
polynomial itself. See examples for details.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">Rational</span><span class="p">,</span> <span class="n">binomial</span><span class="p">,</span> <span class="n">expand_func</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;n&#39;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">binomial</span><span class="p">(</span><span class="mi">15</span><span class="p">,</span> <span class="mi">8</span><span class="p">)</span>
<span class="go">6435</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">binomial</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="go">0</span>
</pre></div>
</div>
<p>Rows of Pascal’s triangle can be generated with the binomial function:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">N</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">8</span><span class="p">):</span>
<span class="gp">... </span>    <span class="nb">print</span><span class="p">([</span><span class="n">binomial</span><span class="p">(</span><span class="n">N</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">N</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)])</span>
<span class="gp">...</span>
<span class="go">[1]</span>
<span class="go">[1, 1]</span>
<span class="go">[1, 2, 1]</span>
<span class="go">[1, 3, 3, 1]</span>
<span class="go">[1, 4, 6, 4, 1]</span>
<span class="go">[1, 5, 10, 10, 5, 1]</span>
<span class="go">[1, 6, 15, 20, 15, 6, 1]</span>
<span class="go">[1, 7, 21, 35, 35, 21, 7, 1]</span>
</pre></div>
</div>
<p>As can a given diagonal, e.g. the 4th diagonal:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">N</span> <span class="o">=</span> <span class="o">-</span><span class="mi">4</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">binomial</span><span class="p">(</span><span class="n">N</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">N</span><span class="p">)]</span>
<span class="go">[1, -4, 10, -20, 35]</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">binomial</span><span class="p">(</span><span class="n">Rational</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">4</span><span class="p">),</span> <span class="mi">3</span><span class="p">)</span>
<span class="go">-5/128</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">binomial</span><span class="p">(</span><span class="n">Rational</span><span class="p">(</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span> <span class="mi">4</span><span class="p">),</span> <span class="mi">3</span><span class="p">)</span>
<span class="go">-195/128</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">binomial</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="go">binomial(n, 3)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">binomial</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">func</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">n**3/6 - n**2/2 + n/3</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expand_func</span><span class="p">(</span><span class="n">binomial</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
<span class="go">n*(n - 2)*(n - 1)/6</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r190"><span class="brackets"><a class="fn-backref" href="#id8">R190</a></span></dt>
<dd><p><a class="reference external" href="https://www.johndcook.com/blog/binomial_coefficients/">https://www.johndcook.com/blog/binomial_coefficients/</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="catalan">
<h2>catalan<a class="headerlink" href="#catalan" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.functions.combinatorial.numbers.catalan">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.functions.combinatorial.numbers.</span></span><span class="sig-name descname"><span class="pre">catalan</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/functions/combinatorial/numbers.py#L1070-L1205"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.functions.combinatorial.numbers.catalan" title="Permalink to this definition">¶</a></dt>
<dd><p>Catalan numbers</p>
<p>The <span class="math notranslate nohighlight">\(n^{th}\)</span> catalan number is given by:</p>
<div class="math notranslate nohighlight">
\[C_n = \frac{1}{n+1} \binom{2n}{n}\]</div>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">catalan(n)</span></code> gives the <span class="math notranslate nohighlight">\(n^{th}\)</span> Catalan number, <span class="math notranslate nohighlight">\(C_n\)</span></p></li>
</ul>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="p">(</span><span class="n">Symbol</span><span class="p">,</span> <span class="n">binomial</span><span class="p">,</span> <span class="n">gamma</span><span class="p">,</span> <span class="n">hyper</span><span class="p">,</span> <span class="n">catalan</span><span class="p">,</span>
<span class="gp">... </span>                   <span class="n">diff</span><span class="p">,</span> <span class="n">combsimp</span><span class="p">,</span> <span class="n">Rational</span><span class="p">,</span> <span class="n">I</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">catalan</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">10</span><span class="p">)]</span>
<span class="go">[1, 2, 5, 14, 42, 132, 429, 1430, 4862]</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;n&quot;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">catalan</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="go">catalan(n)</span>
</pre></div>
</div>
<p>Catalan numbers can be transformed into several other, identical
expressions involving other mathematical functions</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">catalan</span><span class="p">(</span><span class="n">n</span><span class="p">)</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">binomial</span><span class="p">)</span>
<span class="go">binomial(2*n, n)/(n + 1)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">catalan</span><span class="p">(</span><span class="n">n</span><span class="p">)</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">gamma</span><span class="p">)</span>
<span class="go">4**n*gamma(n + 1/2)/(sqrt(pi)*gamma(n + 2))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">catalan</span><span class="p">(</span><span class="n">n</span><span class="p">)</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">hyper</span><span class="p">)</span>
<span class="go">hyper((1 - n, -n), (2,), 1)</span>
</pre></div>
</div>
<p>For some non-integer values of n we can get closed form
expressions by rewriting in terms of gamma functions:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">catalan</span><span class="p">(</span><span class="n">Rational</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">gamma</span><span class="p">)</span>
<span class="go">8/(3*pi)</span>
</pre></div>
</div>
<p>We can differentiate the Catalan numbers C(n) interpreted as a
continuous real function in n:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">diff</span><span class="p">(</span><span class="n">catalan</span><span class="p">(</span><span class="n">n</span><span class="p">),</span> <span class="n">n</span><span class="p">)</span>
<span class="go">(polygamma(0, n + 1/2) - polygamma(0, n + 2) + log(4))*catalan(n)</span>
</pre></div>
</div>
<p>As a more advanced example consider the following ratio
between consecutive numbers:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">combsimp</span><span class="p">((</span><span class="n">catalan</span><span class="p">(</span><span class="n">n</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="n">catalan</span><span class="p">(</span><span class="n">n</span><span class="p">))</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">binomial</span><span class="p">))</span>
<span class="go">2*(2*n + 1)/(n + 2)</span>
</pre></div>
</div>
<p>The Catalan numbers can be generalized to complex numbers:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">catalan</span><span class="p">(</span><span class="n">I</span><span class="p">)</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">gamma</span><span class="p">)</span>
<span class="go">4**I*gamma(1/2 + I)/(sqrt(pi)*gamma(2 + I))</span>
</pre></div>
</div>
<p>and evaluated with arbitrary precision:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">catalan</span><span class="p">(</span><span class="n">I</span><span class="p">)</span><span class="o">.</span><span class="n">evalf</span><span class="p">(</span><span class="mi">20</span><span class="p">)</span>
<span class="go">0.39764993382373624267 - 0.020884341620842555705*I</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.functions.combinatorial.numbers.bell" title="sympy.functions.combinatorial.numbers.bell"><code class="xref py py-obj docutils literal notranslate"><span class="pre">bell</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.bernoulli" title="sympy.functions.combinatorial.numbers.bernoulli"><code class="xref py py-obj docutils literal notranslate"><span class="pre">bernoulli</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.euler" title="sympy.functions.combinatorial.numbers.euler"><code class="xref py py-obj docutils literal notranslate"><span class="pre">euler</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.fibonacci" title="sympy.functions.combinatorial.numbers.fibonacci"><code class="xref py py-obj docutils literal notranslate"><span class="pre">fibonacci</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.harmonic" title="sympy.functions.combinatorial.numbers.harmonic"><code class="xref py py-obj docutils literal notranslate"><span class="pre">harmonic</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.lucas" title="sympy.functions.combinatorial.numbers.lucas"><code class="xref py py-obj docutils literal notranslate"><span class="pre">lucas</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.genocchi" title="sympy.functions.combinatorial.numbers.genocchi"><code class="xref py py-obj docutils literal notranslate"><span class="pre">genocchi</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.partition" title="sympy.functions.combinatorial.numbers.partition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">partition</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.tribonacci" title="sympy.functions.combinatorial.numbers.tribonacci"><code class="xref py py-obj docutils literal notranslate"><span class="pre">tribonacci</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.factorials.binomial" title="sympy.functions.combinatorial.factorials.binomial"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.functions.combinatorial.factorials.binomial</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r191"><span class="brackets"><a class="fn-backref" href="#id9">R191</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Catalan_number">https://en.wikipedia.org/wiki/Catalan_number</a></p>
</dd>
<dt class="label" id="r192"><span class="brackets"><a class="fn-backref" href="#id10">R192</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/CatalanNumber.html">http://mathworld.wolfram.com/CatalanNumber.html</a></p>
</dd>
<dt class="label" id="r193"><span class="brackets"><a class="fn-backref" href="#id11">R193</a></span></dt>
<dd><p><a class="reference external" href="http://functions.wolfram.com/GammaBetaErf/CatalanNumber/">http://functions.wolfram.com/GammaBetaErf/CatalanNumber/</a></p>
</dd>
<dt class="label" id="r194"><span class="brackets"><a class="fn-backref" href="#id12">R194</a></span></dt>
<dd><p><a class="reference external" href="http://geometer.org/mathcircles/catalan.pdf">http://geometer.org/mathcircles/catalan.pdf</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="euler">
<h2>euler<a class="headerlink" href="#euler" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.functions.combinatorial.numbers.euler">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.functions.combinatorial.numbers.</span></span><span class="sig-name descname"><span class="pre">euler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">m</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sym</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/functions/combinatorial/numbers.py#L919-L1061"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.functions.combinatorial.numbers.euler" title="Permalink to this definition">¶</a></dt>
<dd><p>Euler numbers / Euler polynomials</p>
<p>The Euler numbers are given by:</p>
<div class="math notranslate nohighlight">
\[E_{2n} = I \sum_{k=1}^{2n+1} \sum_{j=0}^k \binom{k}{j}
\frac{(-1)^j (k-2j)^{2n+1}}{2^k I^k k}\]</div>
<div class="math notranslate nohighlight">
\[E_{2n+1} = 0\]</div>
<p>Euler numbers and Euler polynomials are related by</p>
<div class="math notranslate nohighlight">
\[E_n = 2^n E_n\left(\frac{1}{2}\right).\]</div>
<p>We compute symbolic Euler polynomials using <a class="reference internal" href="#r199" id="id13"><span>[R199]</span></a></p>
<div class="math notranslate nohighlight">
\[E_n(x) = \sum_{k=0}^n \binom{n}{k} \frac{E_k}{2^k}
\left(x - \frac{1}{2}\right)^{n-k}.\]</div>
<p>However, numerical evaluation of the Euler polynomial is computed
more efficiently (and more accurately) using the mpmath library.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">euler(n)</span></code> gives the <span class="math notranslate nohighlight">\(n^{th}\)</span> Euler number, <span class="math notranslate nohighlight">\(E_n\)</span>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">euler(n,</span> <span class="pre">x)</span></code> gives the <span class="math notranslate nohighlight">\(n^{th}\)</span> Euler polynomial, <span class="math notranslate nohighlight">\(E_n(x)\)</span>.</p></li>
</ul>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">S</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.functions</span> <span class="kn">import</span> <span class="n">euler</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">euler</span><span class="p">(</span><span class="n">n</span><span class="p">)</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">)]</span>
<span class="go">[1, 0, -1, 0, 5, 0, -61, 0, 1385, 0]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;n&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">euler</span><span class="p">(</span><span class="n">n</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">n</span><span class="p">)</span>
<span class="go">euler(3*n)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">euler</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="go">euler(n, x)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">euler</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">euler</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="go">x - 1/2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">euler</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="go">x**2 - x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">euler</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="go">x**3 - 3*x**2/2 + 1/4</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">euler</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="go">x**4 - 2*x**3 + x</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">euler</span><span class="p">(</span><span class="mi">12</span><span class="p">,</span> <span class="n">S</span><span class="o">.</span><span class="n">Half</span><span class="p">)</span>
<span class="go">2702765/4096</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">euler</span><span class="p">(</span><span class="mi">12</span><span class="p">)</span>
<span class="go">2702765</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.functions.combinatorial.numbers.bell" title="sympy.functions.combinatorial.numbers.bell"><code class="xref py py-obj docutils literal notranslate"><span class="pre">bell</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.bernoulli" title="sympy.functions.combinatorial.numbers.bernoulli"><code class="xref py py-obj docutils literal notranslate"><span class="pre">bernoulli</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.catalan" title="sympy.functions.combinatorial.numbers.catalan"><code class="xref py py-obj docutils literal notranslate"><span class="pre">catalan</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.fibonacci" title="sympy.functions.combinatorial.numbers.fibonacci"><code class="xref py py-obj docutils literal notranslate"><span class="pre">fibonacci</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.harmonic" title="sympy.functions.combinatorial.numbers.harmonic"><code class="xref py py-obj docutils literal notranslate"><span class="pre">harmonic</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.lucas" title="sympy.functions.combinatorial.numbers.lucas"><code class="xref py py-obj docutils literal notranslate"><span class="pre">lucas</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.genocchi" title="sympy.functions.combinatorial.numbers.genocchi"><code class="xref py py-obj docutils literal notranslate"><span class="pre">genocchi</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.partition" title="sympy.functions.combinatorial.numbers.partition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">partition</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.tribonacci" title="sympy.functions.combinatorial.numbers.tribonacci"><code class="xref py py-obj docutils literal notranslate"><span class="pre">tribonacci</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r195"><span class="brackets"><a class="fn-backref" href="#id14">R195</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Euler_numbers">https://en.wikipedia.org/wiki/Euler_numbers</a></p>
</dd>
<dt class="label" id="r196"><span class="brackets"><a class="fn-backref" href="#id15">R196</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/EulerNumber.html">http://mathworld.wolfram.com/EulerNumber.html</a></p>
</dd>
<dt class="label" id="r197"><span class="brackets"><a class="fn-backref" href="#id16">R197</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Alternating_permutation">https://en.wikipedia.org/wiki/Alternating_permutation</a></p>
</dd>
<dt class="label" id="r198"><span class="brackets"><a class="fn-backref" href="#id17">R198</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/AlternatingPermutation.html">http://mathworld.wolfram.com/AlternatingPermutation.html</a></p>
</dd>
<dt class="label" id="r199"><span class="brackets">R199</span><span class="fn-backref">(<a href="#id13">1</a>,<a href="#id18">2</a>)</span></dt>
<dd><p><a class="reference external" href="http://dlmf.nist.gov/24.2#ii">http://dlmf.nist.gov/24.2#ii</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="factorial">
<h2>factorial<a class="headerlink" href="#factorial" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.functions.combinatorial.factorials.factorial">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.functions.combinatorial.factorials.</span></span><span class="sig-name descname"><span class="pre">factorial</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/functions/combinatorial/factorials.py#L36-L277"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.functions.combinatorial.factorials.factorial" title="Permalink to this definition">¶</a></dt>
<dd><p>Implementation of factorial function over nonnegative integers.
By convention (consistent with the gamma function and the binomial
coefficients), factorial of a negative integer is complex infinity.</p>
<p>The factorial is very important in combinatorics where it gives
the number of ways in which <span class="math notranslate nohighlight">\(n\)</span> objects can be permuted. It also
arises in calculus, probability, number theory, etc.</p>
<p>There is strict relation of factorial with gamma function. In
fact <span class="math notranslate nohighlight">\(n! = gamma(n+1)\)</span> for nonnegative integers. Rewrite of this
kind is very useful in case of combinatorial simplification.</p>
<p>Computation of the factorial is done using two algorithms. For
small arguments a precomputed look up table is used. However for bigger
input algorithm Prime-Swing is used. It is the fastest algorithm
known and computes <span class="math notranslate nohighlight">\(n!\)</span> via prime factorization of special class
of numbers, called here the ‘Swing Numbers’.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">factorial</span><span class="p">,</span> <span class="n">S</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;n&#39;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">factorial</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="go">1</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">factorial</span><span class="p">(</span><span class="mi">7</span><span class="p">)</span>
<span class="go">5040</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">factorial</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">)</span>
<span class="go">zoo</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">factorial</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="go">factorial(n)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">factorial</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">n</span><span class="p">)</span>
<span class="go">factorial(2*n)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">factorial</span><span class="p">(</span><span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">)</span>
<span class="go">factorial(1/2)</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.functions.combinatorial.factorials.factorial2" title="sympy.functions.combinatorial.factorials.factorial2"><code class="xref py py-obj docutils literal notranslate"><span class="pre">factorial2</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.factorials.RisingFactorial" title="sympy.functions.combinatorial.factorials.RisingFactorial"><code class="xref py py-obj docutils literal notranslate"><span class="pre">RisingFactorial</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.factorials.FallingFactorial" title="sympy.functions.combinatorial.factorials.FallingFactorial"><code class="xref py py-obj docutils literal notranslate"><span class="pre">FallingFactorial</span></code></a></p>
</div>
</dd></dl>

</section>
<section id="subfactorial">
<h2>subfactorial<a class="headerlink" href="#subfactorial" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.functions.combinatorial.factorials.subfactorial">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.functions.combinatorial.factorials.</span></span><span class="sig-name descname"><span class="pre">subfactorial</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">arg</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/functions/combinatorial/factorials.py#L283-L377"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.functions.combinatorial.factorials.subfactorial" title="Permalink to this definition">¶</a></dt>
<dd><p>The subfactorial counts the derangements of n items and is
defined for non-negative integers as:</p>
<div class="math notranslate nohighlight">
\[\begin{split}!n = \begin{cases} 1 &amp; n = 0 \\ 0 &amp; n = 1 \\
(n-1)(!(n-1) + !(n-2)) &amp; n &gt; 1 \end{cases}\end{split}\]</div>
<p>It can also be written as <code class="docutils literal notranslate"><span class="pre">int(round(n!/exp(1)))</span></code> but the
recursive definition with caching is implemented for this function.</p>
<p>An interesting analytic expression is the following <a class="reference internal" href="#r201" id="id19"><span>[R201]</span></a></p>
<div class="math notranslate nohighlight">
\[!x = \Gamma(x + 1, -1)/e\]</div>
<p>which is valid for non-negative integers <span class="math notranslate nohighlight">\(x\)</span>. The above formula
is not very useful incase of non-integers. <span class="math notranslate nohighlight">\(\Gamma(x + 1, -1)\)</span> is
single-valued only for integral arguments <span class="math notranslate nohighlight">\(x\)</span>, elsewhere on the positive
real axis it has an infinite number of branches none of which are real.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">subfactorial</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">n</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">subfactorial</span><span class="p">(</span><span class="n">n</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">subfactorial(n + 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">subfactorial</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="go">44</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.functions.combinatorial.factorials.factorial" title="sympy.functions.combinatorial.factorials.factorial"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.functions.combinatorial.factorials.factorial</span></code></a>, <a class="reference internal" href="../utilities/iterables.html#sympy.utilities.iterables.generate_derangements" title="sympy.utilities.iterables.generate_derangements"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.utilities.iterables.generate_derangements</span></code></a>, <a class="reference internal" href="special.html#sympy.functions.special.gamma_functions.uppergamma" title="sympy.functions.special.gamma_functions.uppergamma"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.functions.special.gamma_functions.uppergamma</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r200"><span class="brackets"><a class="fn-backref" href="#id20">R200</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Subfactorial">https://en.wikipedia.org/wiki/Subfactorial</a></p>
</dd>
<dt class="label" id="r201"><span class="brackets">R201</span><span class="fn-backref">(<a href="#id19">1</a>,<a href="#id21">2</a>)</span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/Subfactorial.html">http://mathworld.wolfram.com/Subfactorial.html</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="factorial2-double-factorial">
<h2>factorial2 / double factorial<a class="headerlink" href="#factorial2-double-factorial" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.functions.combinatorial.factorials.factorial2">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.functions.combinatorial.factorials.</span></span><span class="sig-name descname"><span class="pre">factorial2</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">arg</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/functions/combinatorial/factorials.py#L380-L490"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.functions.combinatorial.factorials.factorial2" title="Permalink to this definition">¶</a></dt>
<dd><p>The double factorial <span class="math notranslate nohighlight">\(n!!\)</span>, not to be confused with <span class="math notranslate nohighlight">\((n!)!\)</span></p>
<p>The double factorial is defined for nonnegative integers and for odd
negative integers as:</p>
<div class="math notranslate nohighlight">
\[\begin{split}n!! = \begin{cases} 1 &amp; n = 0 \\
n(n-2)(n-4) \cdots 1 &amp; n\ \text{positive odd} \\
n(n-2)(n-4) \cdots 2 &amp; n\ \text{positive even} \\
(n+2)!!/(n+2) &amp; n\ \text{negative odd} \end{cases}\end{split}\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">factorial2</span><span class="p">,</span> <span class="n">var</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">var</span><span class="p">(</span><span class="s1">&#39;n&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span>
<span class="go">n</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factorial2</span><span class="p">(</span><span class="n">n</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">factorial2(n + 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factorial2</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="go">15</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factorial2</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factorial2</span><span class="p">(</span><span class="o">-</span><span class="mi">5</span><span class="p">)</span>
<span class="go">1/3</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.functions.combinatorial.factorials.factorial" title="sympy.functions.combinatorial.factorials.factorial"><code class="xref py py-obj docutils literal notranslate"><span class="pre">factorial</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.factorials.RisingFactorial" title="sympy.functions.combinatorial.factorials.RisingFactorial"><code class="xref py py-obj docutils literal notranslate"><span class="pre">RisingFactorial</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.factorials.FallingFactorial" title="sympy.functions.combinatorial.factorials.FallingFactorial"><code class="xref py py-obj docutils literal notranslate"><span class="pre">FallingFactorial</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r202"><span class="brackets"><a class="fn-backref" href="#id22">R202</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Double_factorial">https://en.wikipedia.org/wiki/Double_factorial</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="fallingfactorial">
<h2>FallingFactorial<a class="headerlink" href="#fallingfactorial" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.functions.combinatorial.factorials.FallingFactorial">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.functions.combinatorial.factorials.</span></span><span class="sig-name descname"><span class="pre">FallingFactorial</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/functions/combinatorial/factorials.py#L657-L808"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.functions.combinatorial.factorials.FallingFactorial" title="Permalink to this definition">¶</a></dt>
<dd><p>Falling factorial (related to rising factorial) is a double valued
function arising in concrete mathematics, hypergeometric functions
and series expansions. It is defined by</p>
<div class="math notranslate nohighlight">
\[ff(x,k) = x \cdot (x-1) \cdots (x-k+1)\]</div>
<p>where <span class="math notranslate nohighlight">\(x\)</span> can be arbitrary expression and <span class="math notranslate nohighlight">\(k\)</span> is an integer. For
more information check “Concrete mathematics” by Graham, pp. 66
or visit <a class="reference external" href="http://mathworld.wolfram.com/FallingFactorial.html">http://mathworld.wolfram.com/FallingFactorial.html</a> page.</p>
<p>When <span class="math notranslate nohighlight">\(x\)</span> is a Poly instance of degree &gt;= 1 with single variable,
<span class="math notranslate nohighlight">\(ff(x,k) = x(y) \cdot x(y-1) \cdots x(y-k+1)\)</span>, where <span class="math notranslate nohighlight">\(y\)</span> is the
variable of <span class="math notranslate nohighlight">\(x\)</span>. This is as described in Peter Paule, “Greatest
Factorial Factorization and Symbolic Summation”, Journal of
Symbolic Computation, vol. 20, pp. 235-268, 1995.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">ff</span><span class="p">,</span> <span class="n">Poly</span><span class="p">,</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;n&#39;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">ff</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ff</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="go">120</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ff</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span> <span class="o">==</span> <span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="mi">3</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="mi">4</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ff</span><span class="p">(</span><span class="n">Poly</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">x</span><span class="p">),</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">Poly(x**4 - 2*x**3 + x**2, x, domain=&#39;ZZ&#39;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ff</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
<span class="go">factorial(n)</span>
</pre></div>
</div>
<p>Rewriting is complicated unless the relationship between
the arguments is known, but falling factorial can
be rewritten in terms of gamma, factorial and binomial
and rising factorial.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">factorial</span><span class="p">,</span> <span class="n">rf</span><span class="p">,</span> <span class="n">gamma</span><span class="p">,</span> <span class="n">binomial</span><span class="p">,</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;n&#39;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">F</span> <span class="o">=</span> <span class="n">ff</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">n</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="p">(</span><span class="n">rf</span><span class="p">,</span> <span class="n">ff</span><span class="p">,</span> <span class="n">factorial</span><span class="p">,</span> <span class="n">binomial</span><span class="p">,</span> <span class="n">gamma</span><span class="p">):</span>
<span class="gp">... </span> <span class="n">F</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
<span class="gp">...</span>
<span class="go">RisingFactorial(3, n - 2)</span>
<span class="go">FallingFactorial(n, n - 2)</span>
<span class="go">factorial(n)/2</span>
<span class="go">binomial(n, n - 2)*factorial(n - 2)</span>
<span class="go">gamma(n + 1)/2</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.functions.combinatorial.factorials.factorial" title="sympy.functions.combinatorial.factorials.factorial"><code class="xref py py-obj docutils literal notranslate"><span class="pre">factorial</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.factorials.factorial2" title="sympy.functions.combinatorial.factorials.factorial2"><code class="xref py py-obj docutils literal notranslate"><span class="pre">factorial2</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.factorials.RisingFactorial" title="sympy.functions.combinatorial.factorials.RisingFactorial"><code class="xref py py-obj docutils literal notranslate"><span class="pre">RisingFactorial</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r203"><span class="brackets"><a class="fn-backref" href="#id23">R203</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/FallingFactorial.html">http://mathworld.wolfram.com/FallingFactorial.html</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="fibonacci">
<h2>fibonacci<a class="headerlink" href="#fibonacci" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.functions.combinatorial.numbers.fibonacci">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.functions.combinatorial.numbers.</span></span><span class="sig-name descname"><span class="pre">fibonacci</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sym</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/functions/combinatorial/numbers.py#L172-L245"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.functions.combinatorial.numbers.fibonacci" title="Permalink to this definition">¶</a></dt>
<dd><p>Fibonacci numbers / Fibonacci polynomials</p>
<p>The Fibonacci numbers are the integer sequence defined by the
initial terms <span class="math notranslate nohighlight">\(F_0 = 0\)</span>, <span class="math notranslate nohighlight">\(F_1 = 1\)</span> and the two-term recurrence
relation <span class="math notranslate nohighlight">\(F_n = F_{n-1} + F_{n-2}\)</span>.  This definition
extended to arbitrary real and complex arguments using
the formula</p>
<div class="math notranslate nohighlight">
\[F_z = \frac{\phi^z - \cos(\pi z) \phi^{-z}}{\sqrt 5}\]</div>
<p>The Fibonacci polynomials are defined by <span class="math notranslate nohighlight">\(F_1(x) = 1\)</span>,
<span class="math notranslate nohighlight">\(F_2(x) = x\)</span>, and <span class="math notranslate nohighlight">\(F_n(x) = x*F_{n-1}(x) + F_{n-2}(x)\)</span> for <span class="math notranslate nohighlight">\(n &gt; 2\)</span>.
For all positive integers <span class="math notranslate nohighlight">\(n\)</span>, <span class="math notranslate nohighlight">\(F_n(1) = F_n\)</span>.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">fibonacci(n)</span></code> gives the <span class="math notranslate nohighlight">\(n^{th}\)</span> Fibonacci number, <span class="math notranslate nohighlight">\(F_n\)</span></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">fibonacci(n,</span> <span class="pre">x)</span></code> gives the <span class="math notranslate nohighlight">\(n^{th}\)</span> Fibonacci polynomial in <span class="math notranslate nohighlight">\(x\)</span>, <span class="math notranslate nohighlight">\(F_n(x)\)</span></p></li>
</ul>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">fibonacci</span><span class="p">,</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">fibonacci</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">11</span><span class="p">)]</span>
<span class="go">[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">fibonacci</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;t&#39;</span><span class="p">))</span>
<span class="go">t**4 + 3*t**2 + 1</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.functions.combinatorial.numbers.bell" title="sympy.functions.combinatorial.numbers.bell"><code class="xref py py-obj docutils literal notranslate"><span class="pre">bell</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.bernoulli" title="sympy.functions.combinatorial.numbers.bernoulli"><code class="xref py py-obj docutils literal notranslate"><span class="pre">bernoulli</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.catalan" title="sympy.functions.combinatorial.numbers.catalan"><code class="xref py py-obj docutils literal notranslate"><span class="pre">catalan</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.euler" title="sympy.functions.combinatorial.numbers.euler"><code class="xref py py-obj docutils literal notranslate"><span class="pre">euler</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.harmonic" title="sympy.functions.combinatorial.numbers.harmonic"><code class="xref py py-obj docutils literal notranslate"><span class="pre">harmonic</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.lucas" title="sympy.functions.combinatorial.numbers.lucas"><code class="xref py py-obj docutils literal notranslate"><span class="pre">lucas</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.genocchi" title="sympy.functions.combinatorial.numbers.genocchi"><code class="xref py py-obj docutils literal notranslate"><span class="pre">genocchi</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.partition" title="sympy.functions.combinatorial.numbers.partition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">partition</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.tribonacci" title="sympy.functions.combinatorial.numbers.tribonacci"><code class="xref py py-obj docutils literal notranslate"><span class="pre">tribonacci</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r204"><span class="brackets"><a class="fn-backref" href="#id24">R204</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Fibonacci_number">https://en.wikipedia.org/wiki/Fibonacci_number</a></p>
</dd>
<dt class="label" id="r205"><span class="brackets"><a class="fn-backref" href="#id25">R205</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/FibonacciNumber.html">http://mathworld.wolfram.com/FibonacciNumber.html</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="tribonacci">
<h2>tribonacci<a class="headerlink" href="#tribonacci" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.functions.combinatorial.numbers.tribonacci">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.functions.combinatorial.numbers.</span></span><span class="sig-name descname"><span class="pre">tribonacci</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sym</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/functions/combinatorial/numbers.py#L306-L383"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.functions.combinatorial.numbers.tribonacci" title="Permalink to this definition">¶</a></dt>
<dd><p>Tribonacci numbers / Tribonacci polynomials</p>
<p>The Tribonacci numbers are the integer sequence defined by the
initial terms <span class="math notranslate nohighlight">\(T_0 = 0\)</span>, <span class="math notranslate nohighlight">\(T_1 = 1\)</span>, <span class="math notranslate nohighlight">\(T_2 = 1\)</span> and the three-term
recurrence relation <span class="math notranslate nohighlight">\(T_n = T_{n-1} + T_{n-2} + T_{n-3}\)</span>.</p>
<p>The Tribonacci polynomials are defined by <span class="math notranslate nohighlight">\(T_0(x) = 0\)</span>, <span class="math notranslate nohighlight">\(T_1(x) = 1\)</span>,
<span class="math notranslate nohighlight">\(T_2(x) = x^2\)</span>, and <span class="math notranslate nohighlight">\(T_n(x) = x^2 T_{n-1}(x) + x T_{n-2}(x) + T_{n-3}(x)\)</span>
for <span class="math notranslate nohighlight">\(n &gt; 2\)</span>.  For all positive integers <span class="math notranslate nohighlight">\(n\)</span>, <span class="math notranslate nohighlight">\(T_n(1) = T_n\)</span>.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">tribonacci(n)</span></code> gives the <span class="math notranslate nohighlight">\(n^{th}\)</span> Tribonacci number, <span class="math notranslate nohighlight">\(T_n\)</span></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">tribonacci(n,</span> <span class="pre">x)</span></code> gives the <span class="math notranslate nohighlight">\(n^{th}\)</span> Tribonacci polynomial in <span class="math notranslate nohighlight">\(x\)</span>, <span class="math notranslate nohighlight">\(T_n(x)\)</span></p></li>
</ul>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">tribonacci</span><span class="p">,</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">tribonacci</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">11</span><span class="p">)]</span>
<span class="go">[0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">tribonacci</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;t&#39;</span><span class="p">))</span>
<span class="go">t**8 + 3*t**5 + 3*t**2</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.functions.combinatorial.numbers.bell" title="sympy.functions.combinatorial.numbers.bell"><code class="xref py py-obj docutils literal notranslate"><span class="pre">bell</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.bernoulli" title="sympy.functions.combinatorial.numbers.bernoulli"><code class="xref py py-obj docutils literal notranslate"><span class="pre">bernoulli</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.catalan" title="sympy.functions.combinatorial.numbers.catalan"><code class="xref py py-obj docutils literal notranslate"><span class="pre">catalan</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.euler" title="sympy.functions.combinatorial.numbers.euler"><code class="xref py py-obj docutils literal notranslate"><span class="pre">euler</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.fibonacci" title="sympy.functions.combinatorial.numbers.fibonacci"><code class="xref py py-obj docutils literal notranslate"><span class="pre">fibonacci</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.harmonic" title="sympy.functions.combinatorial.numbers.harmonic"><code class="xref py py-obj docutils literal notranslate"><span class="pre">harmonic</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.lucas" title="sympy.functions.combinatorial.numbers.lucas"><code class="xref py py-obj docutils literal notranslate"><span class="pre">lucas</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.genocchi" title="sympy.functions.combinatorial.numbers.genocchi"><code class="xref py py-obj docutils literal notranslate"><span class="pre">genocchi</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.partition" title="sympy.functions.combinatorial.numbers.partition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">partition</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r206"><span class="brackets"><a class="fn-backref" href="#id26">R206</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Generalizations_of_Fibonacci_numbers#Tribonacci_numbers">https://en.wikipedia.org/wiki/Generalizations_of_Fibonacci_numbers#Tribonacci_numbers</a></p>
</dd>
<dt class="label" id="r207"><span class="brackets"><a class="fn-backref" href="#id27">R207</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/TribonacciNumber.html">http://mathworld.wolfram.com/TribonacciNumber.html</a></p>
</dd>
<dt class="label" id="r208"><span class="brackets"><a class="fn-backref" href="#id28">R208</a></span></dt>
<dd><p><a class="reference external" href="https://oeis.org/A000073">https://oeis.org/A000073</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="harmonic">
<h2>harmonic<a class="headerlink" href="#harmonic" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.functions.combinatorial.numbers.harmonic">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.functions.combinatorial.numbers.</span></span><span class="sig-name descname"><span class="pre">harmonic</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">m</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/functions/combinatorial/numbers.py#L687-L909"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.functions.combinatorial.numbers.harmonic" title="Permalink to this definition">¶</a></dt>
<dd><p>Harmonic numbers</p>
<p>The nth harmonic number is given by <span class="math notranslate nohighlight">\(\operatorname{H}_{n} =
1 + \frac{1}{2} + \frac{1}{3} + \ldots + \frac{1}{n}\)</span>.</p>
<p>More generally:</p>
<div class="math notranslate nohighlight">
\[\operatorname{H}_{n,m} = \sum_{k=1}^{n} \frac{1}{k^m}\]</div>
<p>As <span class="math notranslate nohighlight">\(n \rightarrow \infty\)</span>, <span class="math notranslate nohighlight">\(\operatorname{H}_{n,m} \rightarrow \zeta(m)\)</span>,
the Riemann zeta function.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">harmonic(n)</span></code> gives the nth harmonic number, <span class="math notranslate nohighlight">\(\operatorname{H}_n\)</span></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">harmonic(n,</span> <span class="pre">m)</span></code> gives the nth generalized harmonic number
of order <span class="math notranslate nohighlight">\(m\)</span>, <span class="math notranslate nohighlight">\(\operatorname{H}_{n,m}\)</span>, where
<code class="docutils literal notranslate"><span class="pre">harmonic(n)</span> <span class="pre">==</span> <span class="pre">harmonic(n,</span> <span class="pre">1)</span></code></p></li>
</ul>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">harmonic</span><span class="p">,</span> <span class="n">oo</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">harmonic</span><span class="p">(</span><span class="n">n</span><span class="p">)</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">6</span><span class="p">)]</span>
<span class="go">[0, 1, 3/2, 11/6, 25/12, 137/60]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">harmonic</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">6</span><span class="p">)]</span>
<span class="go">[0, 1, 5/4, 49/36, 205/144, 5269/3600]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">harmonic</span><span class="p">(</span><span class="n">oo</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">pi**2/6</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">Sum</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;n&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">harmonic</span><span class="p">(</span><span class="n">n</span><span class="p">)</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">Sum</span><span class="p">)</span>
<span class="go">Sum(1/_k, (_k, 1, n))</span>
</pre></div>
</div>
<p>We can evaluate harmonic numbers for all integral and positive
rational arguments:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">S</span><span class="p">,</span> <span class="n">expand_func</span><span class="p">,</span> <span class="n">simplify</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">harmonic</span><span class="p">(</span><span class="mi">8</span><span class="p">)</span>
<span class="go">761/280</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">harmonic</span><span class="p">(</span><span class="mi">11</span><span class="p">)</span>
<span class="go">83711/27720</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">H</span> <span class="o">=</span> <span class="n">harmonic</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">S</span><span class="p">(</span><span class="mi">3</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">H</span>
<span class="go">harmonic(1/3)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">He</span> <span class="o">=</span> <span class="n">expand_func</span><span class="p">(</span><span class="n">H</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">He</span>
<span class="go">-log(6) - sqrt(3)*pi/6 + 2*Sum(log(sin(_k*pi/3))*cos(2*_k*pi/3), (_k, 1, 1))</span>
<span class="go">                       + 3*Sum(1/(3*_k + 1), (_k, 0, 0))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">He</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">-log(6) - sqrt(3)*pi/6 - log(sqrt(3)/2) + 3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">H</span> <span class="o">=</span> <span class="n">harmonic</span><span class="p">(</span><span class="mi">25</span><span class="o">/</span><span class="n">S</span><span class="p">(</span><span class="mi">7</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">He</span> <span class="o">=</span> <span class="n">simplify</span><span class="p">(</span><span class="n">expand_func</span><span class="p">(</span><span class="n">H</span><span class="p">)</span><span class="o">.</span><span class="n">doit</span><span class="p">())</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">He</span>
<span class="go">log(sin(2*pi/7)**(2*cos(16*pi/7))/(14*sin(pi/7)**(2*cos(pi/7))*cos(pi/14)**(2*sin(pi/14)))) + pi*tan(pi/14)/2 + 30247/9900</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">He</span><span class="o">.</span><span class="n">n</span><span class="p">(</span><span class="mi">40</span><span class="p">)</span>
<span class="go">1.983697455232980674869851942390639915940</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">harmonic</span><span class="p">(</span><span class="mi">25</span><span class="o">/</span><span class="n">S</span><span class="p">(</span><span class="mi">7</span><span class="p">))</span><span class="o">.</span><span class="n">n</span><span class="p">(</span><span class="mi">40</span><span class="p">)</span>
<span class="go">1.983697455232980674869851942390639915940</span>
</pre></div>
</div>
<p>We can rewrite harmonic numbers in terms of polygamma functions:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">digamma</span><span class="p">,</span> <span class="n">polygamma</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;m&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">harmonic</span><span class="p">(</span><span class="n">n</span><span class="p">)</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">digamma</span><span class="p">)</span>
<span class="go">polygamma(0, n + 1) + EulerGamma</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">harmonic</span><span class="p">(</span><span class="n">n</span><span class="p">)</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">polygamma</span><span class="p">)</span>
<span class="go">polygamma(0, n + 1) + EulerGamma</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">harmonic</span><span class="p">(</span><span class="n">n</span><span class="p">,</span><span class="mi">3</span><span class="p">)</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">polygamma</span><span class="p">)</span>
<span class="go">polygamma(2, n + 1)/2 - polygamma(2, 1)/2</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">harmonic</span><span class="p">(</span><span class="n">n</span><span class="p">,</span><span class="n">m</span><span class="p">)</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">polygamma</span><span class="p">)</span>
<span class="go">(-1)**m*(polygamma(m - 1, 1) - polygamma(m - 1, n + 1))/factorial(m - 1)</span>
</pre></div>
</div>
<p>Integer offsets in the argument can be pulled out:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">expand_func</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expand_func</span><span class="p">(</span><span class="n">harmonic</span><span class="p">(</span><span class="n">n</span><span class="o">+</span><span class="mi">4</span><span class="p">))</span>
<span class="go">harmonic(n) + 1/(n + 4) + 1/(n + 3) + 1/(n + 2) + 1/(n + 1)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expand_func</span><span class="p">(</span><span class="n">harmonic</span><span class="p">(</span><span class="n">n</span><span class="o">-</span><span class="mi">4</span><span class="p">))</span>
<span class="go">harmonic(n) - 1/(n - 1) - 1/(n - 2) - 1/(n - 3) - 1/n</span>
</pre></div>
</div>
<p>Some limits can be computed as well:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">limit</span><span class="p">,</span> <span class="n">oo</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">limit</span><span class="p">(</span><span class="n">harmonic</span><span class="p">(</span><span class="n">n</span><span class="p">),</span> <span class="n">n</span><span class="p">,</span> <span class="n">oo</span><span class="p">)</span>
<span class="go">oo</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">limit</span><span class="p">(</span><span class="n">harmonic</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span> <span class="n">n</span><span class="p">,</span> <span class="n">oo</span><span class="p">)</span>
<span class="go">pi**2/6</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">limit</span><span class="p">(</span><span class="n">harmonic</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">3</span><span class="p">),</span> <span class="n">n</span><span class="p">,</span> <span class="n">oo</span><span class="p">)</span>
<span class="go">-polygamma(2, 1)/2</span>
</pre></div>
</div>
<p>However we can not compute the general relation yet:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">limit</span><span class="p">(</span><span class="n">harmonic</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">),</span> <span class="n">n</span><span class="p">,</span> <span class="n">oo</span><span class="p">)</span>
<span class="go">harmonic(oo, m)</span>
</pre></div>
</div>
<p>which equals <code class="docutils literal notranslate"><span class="pre">zeta(m)</span></code> for <code class="docutils literal notranslate"><span class="pre">m</span> <span class="pre">&gt;</span> <span class="pre">1</span></code>.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.functions.combinatorial.numbers.bell" title="sympy.functions.combinatorial.numbers.bell"><code class="xref py py-obj docutils literal notranslate"><span class="pre">bell</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.bernoulli" title="sympy.functions.combinatorial.numbers.bernoulli"><code class="xref py py-obj docutils literal notranslate"><span class="pre">bernoulli</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.catalan" title="sympy.functions.combinatorial.numbers.catalan"><code class="xref py py-obj docutils literal notranslate"><span class="pre">catalan</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.euler" title="sympy.functions.combinatorial.numbers.euler"><code class="xref py py-obj docutils literal notranslate"><span class="pre">euler</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.fibonacci" title="sympy.functions.combinatorial.numbers.fibonacci"><code class="xref py py-obj docutils literal notranslate"><span class="pre">fibonacci</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.lucas" title="sympy.functions.combinatorial.numbers.lucas"><code class="xref py py-obj docutils literal notranslate"><span class="pre">lucas</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.genocchi" title="sympy.functions.combinatorial.numbers.genocchi"><code class="xref py py-obj docutils literal notranslate"><span class="pre">genocchi</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.partition" title="sympy.functions.combinatorial.numbers.partition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">partition</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.tribonacci" title="sympy.functions.combinatorial.numbers.tribonacci"><code class="xref py py-obj docutils literal notranslate"><span class="pre">tribonacci</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r209"><span class="brackets"><a class="fn-backref" href="#id29">R209</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Harmonic_number">https://en.wikipedia.org/wiki/Harmonic_number</a></p>
</dd>
<dt class="label" id="r210"><span class="brackets"><a class="fn-backref" href="#id30">R210</a></span></dt>
<dd><p><a class="reference external" href="http://functions.wolfram.com/GammaBetaErf/HarmonicNumber/">http://functions.wolfram.com/GammaBetaErf/HarmonicNumber/</a></p>
</dd>
<dt class="label" id="r211"><span class="brackets"><a class="fn-backref" href="#id31">R211</a></span></dt>
<dd><p><a class="reference external" href="http://functions.wolfram.com/GammaBetaErf/HarmonicNumber2/">http://functions.wolfram.com/GammaBetaErf/HarmonicNumber2/</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="lucas">
<h2>lucas<a class="headerlink" href="#lucas" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.functions.combinatorial.numbers.lucas">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.functions.combinatorial.numbers.</span></span><span class="sig-name descname"><span class="pre">lucas</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/functions/combinatorial/numbers.py#L255-L296"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.functions.combinatorial.numbers.lucas" title="Permalink to this definition">¶</a></dt>
<dd><p>Lucas numbers</p>
<p>Lucas numbers satisfy a recurrence relation similar to that of
the Fibonacci sequence, in which each term is the sum of the
preceding two. They are generated by choosing the initial
values <span class="math notranslate nohighlight">\(L_0 = 2\)</span> and <span class="math notranslate nohighlight">\(L_1 = 1\)</span>.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">lucas(n)</span></code> gives the <span class="math notranslate nohighlight">\(n^{th}\)</span> Lucas number</p></li>
</ul>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">lucas</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">lucas</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">11</span><span class="p">)]</span>
<span class="go">[2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123]</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.functions.combinatorial.numbers.bell" title="sympy.functions.combinatorial.numbers.bell"><code class="xref py py-obj docutils literal notranslate"><span class="pre">bell</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.bernoulli" title="sympy.functions.combinatorial.numbers.bernoulli"><code class="xref py py-obj docutils literal notranslate"><span class="pre">bernoulli</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.catalan" title="sympy.functions.combinatorial.numbers.catalan"><code class="xref py py-obj docutils literal notranslate"><span class="pre">catalan</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.euler" title="sympy.functions.combinatorial.numbers.euler"><code class="xref py py-obj docutils literal notranslate"><span class="pre">euler</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.fibonacci" title="sympy.functions.combinatorial.numbers.fibonacci"><code class="xref py py-obj docutils literal notranslate"><span class="pre">fibonacci</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.harmonic" title="sympy.functions.combinatorial.numbers.harmonic"><code class="xref py py-obj docutils literal notranslate"><span class="pre">harmonic</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.genocchi" title="sympy.functions.combinatorial.numbers.genocchi"><code class="xref py py-obj docutils literal notranslate"><span class="pre">genocchi</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.partition" title="sympy.functions.combinatorial.numbers.partition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">partition</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.tribonacci" title="sympy.functions.combinatorial.numbers.tribonacci"><code class="xref py py-obj docutils literal notranslate"><span class="pre">tribonacci</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r212"><span class="brackets"><a class="fn-backref" href="#id32">R212</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Lucas_number">https://en.wikipedia.org/wiki/Lucas_number</a></p>
</dd>
<dt class="label" id="r213"><span class="brackets"><a class="fn-backref" href="#id33">R213</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/LucasNumber.html">http://mathworld.wolfram.com/LucasNumber.html</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="genocchi">
<h2>genocchi<a class="headerlink" href="#genocchi" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.functions.combinatorial.numbers.genocchi">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.functions.combinatorial.numbers.</span></span><span class="sig-name descname"><span class="pre">genocchi</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/functions/combinatorial/numbers.py#L1216-L1304"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.functions.combinatorial.numbers.genocchi" title="Permalink to this definition">¶</a></dt>
<dd><p>Genocchi numbers</p>
<p>The Genocchi numbers are a sequence of integers <span class="math notranslate nohighlight">\(G_n\)</span> that satisfy the
relation:</p>
<div class="math notranslate nohighlight">
\[\frac{2t}{e^t + 1} = \sum_{n=1}^\infty \frac{G_n t^n}{n!}\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.functions</span> <span class="kn">import</span> <span class="n">genocchi</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">genocchi</span><span class="p">(</span><span class="n">n</span><span class="p">)</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">9</span><span class="p">)]</span>
<span class="go">[1, -1, 0, 1, 0, -3, 0, 17]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;n&#39;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">genocchi</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">n</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">0</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.functions.combinatorial.numbers.bell" title="sympy.functions.combinatorial.numbers.bell"><code class="xref py py-obj docutils literal notranslate"><span class="pre">bell</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.bernoulli" title="sympy.functions.combinatorial.numbers.bernoulli"><code class="xref py py-obj docutils literal notranslate"><span class="pre">bernoulli</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.catalan" title="sympy.functions.combinatorial.numbers.catalan"><code class="xref py py-obj docutils literal notranslate"><span class="pre">catalan</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.euler" title="sympy.functions.combinatorial.numbers.euler"><code class="xref py py-obj docutils literal notranslate"><span class="pre">euler</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.fibonacci" title="sympy.functions.combinatorial.numbers.fibonacci"><code class="xref py py-obj docutils literal notranslate"><span class="pre">fibonacci</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.harmonic" title="sympy.functions.combinatorial.numbers.harmonic"><code class="xref py py-obj docutils literal notranslate"><span class="pre">harmonic</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.lucas" title="sympy.functions.combinatorial.numbers.lucas"><code class="xref py py-obj docutils literal notranslate"><span class="pre">lucas</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.partition" title="sympy.functions.combinatorial.numbers.partition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">partition</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.tribonacci" title="sympy.functions.combinatorial.numbers.tribonacci"><code class="xref py py-obj docutils literal notranslate"><span class="pre">tribonacci</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r214"><span class="brackets"><a class="fn-backref" href="#id34">R214</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Genocchi_number">https://en.wikipedia.org/wiki/Genocchi_number</a></p>
</dd>
<dt class="label" id="r215"><span class="brackets"><a class="fn-backref" href="#id35">R215</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/GenocchiNumber.html">http://mathworld.wolfram.com/GenocchiNumber.html</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="partition">
<h2>partition<a class="headerlink" href="#partition" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.functions.combinatorial.numbers.partition">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.functions.combinatorial.numbers.</span></span><span class="sig-name descname"><span class="pre">partition</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/functions/combinatorial/numbers.py#L1314-L1400"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.functions.combinatorial.numbers.partition" title="Permalink to this definition">¶</a></dt>
<dd><p>Partition numbers</p>
<p>The Partition numbers are a sequence of integers <span class="math notranslate nohighlight">\(p_n\)</span> that represent the
number of distinct ways of representing <span class="math notranslate nohighlight">\(n\)</span> as a sum of natural numbers
(with order irrelevant). The generating function for <span class="math notranslate nohighlight">\(p_n\)</span> is given by:</p>
<div class="math notranslate nohighlight">
\[\sum_{n=0}^\infty p_n x^n = \prod_{k=1}^\infty (1 - x^k)^{-1}\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.functions</span> <span class="kn">import</span> <span class="n">partition</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">partition</span><span class="p">(</span><span class="n">n</span><span class="p">)</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">9</span><span class="p">)]</span>
<span class="go">[1, 1, 2, 3, 5, 7, 11, 15, 22]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;n&#39;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">negative</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">partition</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="go">0</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.functions.combinatorial.numbers.bell" title="sympy.functions.combinatorial.numbers.bell"><code class="xref py py-obj docutils literal notranslate"><span class="pre">bell</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.bernoulli" title="sympy.functions.combinatorial.numbers.bernoulli"><code class="xref py py-obj docutils literal notranslate"><span class="pre">bernoulli</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.catalan" title="sympy.functions.combinatorial.numbers.catalan"><code class="xref py py-obj docutils literal notranslate"><span class="pre">catalan</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.euler" title="sympy.functions.combinatorial.numbers.euler"><code class="xref py py-obj docutils literal notranslate"><span class="pre">euler</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.fibonacci" title="sympy.functions.combinatorial.numbers.fibonacci"><code class="xref py py-obj docutils literal notranslate"><span class="pre">fibonacci</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.harmonic" title="sympy.functions.combinatorial.numbers.harmonic"><code class="xref py py-obj docutils literal notranslate"><span class="pre">harmonic</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.lucas" title="sympy.functions.combinatorial.numbers.lucas"><code class="xref py py-obj docutils literal notranslate"><span class="pre">lucas</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.genocchi" title="sympy.functions.combinatorial.numbers.genocchi"><code class="xref py py-obj docutils literal notranslate"><span class="pre">genocchi</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.tribonacci" title="sympy.functions.combinatorial.numbers.tribonacci"><code class="xref py py-obj docutils literal notranslate"><span class="pre">tribonacci</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r216"><span class="brackets"><a class="fn-backref" href="#id36">R216</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Partition_(number_theory)">https://en.wikipedia.org/wiki/Partition_(number_theory%29</a></p>
</dd>
<dt class="label" id="r217"><span class="brackets"><a class="fn-backref" href="#id37">R217</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Pentagonal_number_theorem">https://en.wikipedia.org/wiki/Pentagonal_number_theorem</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="multifactorial">
<h2>MultiFactorial<a class="headerlink" href="#multifactorial" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.functions.combinatorial.factorials.MultiFactorial">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.functions.combinatorial.factorials.</span></span><span class="sig-name descname"><span class="pre">MultiFactorial</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/functions/combinatorial/factorials.py#L279-L280"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.functions.combinatorial.factorials.MultiFactorial" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</section>
<section id="risingfactorial">
<h2>RisingFactorial<a class="headerlink" href="#risingfactorial" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.functions.combinatorial.factorials.RisingFactorial">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.functions.combinatorial.factorials.</span></span><span class="sig-name descname"><span class="pre">RisingFactorial</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/functions/combinatorial/factorials.py#L498-L654"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.functions.combinatorial.factorials.RisingFactorial" title="Permalink to this definition">¶</a></dt>
<dd><p>Rising factorial (also called Pochhammer symbol) is a double valued
function arising in concrete mathematics, hypergeometric functions
and series expansions. It is defined by:</p>
<div class="math notranslate nohighlight">
\[rf(x,k) = x \cdot (x+1) \cdots (x+k-1)\]</div>
<p>where <span class="math notranslate nohighlight">\(x\)</span> can be arbitrary expression and <span class="math notranslate nohighlight">\(k\)</span> is an integer. For
more information check “Concrete mathematics” by Graham, pp. 66
or visit <a class="reference external" href="http://mathworld.wolfram.com/RisingFactorial.html">http://mathworld.wolfram.com/RisingFactorial.html</a> page.</p>
<p>When <span class="math notranslate nohighlight">\(x\)</span> is a Poly instance of degree &gt;= 1 with a single variable,
<span class="math notranslate nohighlight">\(rf(x,k) = x(y) \cdot x(y+1) \cdots x(y+k-1)\)</span>, where <span class="math notranslate nohighlight">\(y\)</span> is the
variable of <span class="math notranslate nohighlight">\(x\)</span>. This is as described in Peter Paule, “Greatest
Factorial Factorization and Symbolic Summation”, Journal of
Symbolic Computation, vol. 20, pp. 235-268, 1995.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">rf</span><span class="p">,</span> <span class="n">Poly</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rf</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rf</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="go">120</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rf</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span> <span class="o">==</span> <span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="mi">2</span> <span class="o">+</span> <span class="n">x</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="mi">3</span> <span class="o">+</span> <span class="n">x</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="mi">4</span> <span class="o">+</span> <span class="n">x</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rf</span><span class="p">(</span><span class="n">Poly</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">3</span><span class="p">,</span> <span class="n">x</span><span class="p">),</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">Poly(x**6 + 3*x**5 + 3*x**4 + x**3, x, domain=&#39;ZZ&#39;)</span>
</pre></div>
</div>
<p>Rewriting is complicated unless the relationship between
the arguments is known, but rising factorial can
be rewritten in terms of gamma, factorial and binomial
and falling factorial.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">factorial</span><span class="p">,</span> <span class="n">ff</span><span class="p">,</span> <span class="n">binomial</span><span class="p">,</span> <span class="n">gamma</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;n&#39;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">R</span> <span class="o">=</span> <span class="n">rf</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">n</span> <span class="o">+</span> <span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="p">(</span><span class="n">rf</span><span class="p">,</span> <span class="n">ff</span><span class="p">,</span> <span class="n">factorial</span><span class="p">,</span> <span class="n">binomial</span><span class="p">,</span> <span class="n">gamma</span><span class="p">):</span>
<span class="gp">... </span> <span class="n">R</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
<span class="gp">...</span>
<span class="go">RisingFactorial(n, n + 2)</span>
<span class="go">FallingFactorial(2*n + 1, n + 2)</span>
<span class="go">factorial(2*n + 1)/factorial(n - 1)</span>
<span class="go">binomial(2*n + 1, n + 2)*factorial(n + 2)</span>
<span class="go">gamma(2*n + 2)/gamma(n)</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.functions.combinatorial.factorials.factorial" title="sympy.functions.combinatorial.factorials.factorial"><code class="xref py py-obj docutils literal notranslate"><span class="pre">factorial</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.factorials.factorial2" title="sympy.functions.combinatorial.factorials.factorial2"><code class="xref py py-obj docutils literal notranslate"><span class="pre">factorial2</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.factorials.FallingFactorial" title="sympy.functions.combinatorial.factorials.FallingFactorial"><code class="xref py py-obj docutils literal notranslate"><span class="pre">FallingFactorial</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r218"><span class="brackets"><a class="fn-backref" href="#id38">R218</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Pochhammer_symbol">https://en.wikipedia.org/wiki/Pochhammer_symbol</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="stirling">
<h2>stirling<a class="headerlink" href="#stirling" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.functions.combinatorial.numbers.stirling">
<span class="sig-prename descclassname"><span class="pre">sympy.functions.combinatorial.numbers.</span></span><span class="sig-name descname"><span class="pre">stirling</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">d</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">kind</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">2</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">signed</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/functions/combinatorial/numbers.py#L1773-L1878"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.functions.combinatorial.numbers.stirling" title="Permalink to this definition">¶</a></dt>
<dd><p>Return Stirling number <span class="math notranslate nohighlight">\(S(n, k)\)</span> of the first or second (default) kind.</p>
<p>The sum of all Stirling numbers of the second kind for <span class="math notranslate nohighlight">\(k = 1\)</span>
through <span class="math notranslate nohighlight">\(n\)</span> is <code class="docutils literal notranslate"><span class="pre">bell(n)</span></code>. The recurrence relationship for these numbers
is:</p>
<div class="math notranslate nohighlight">
\[{0 \brace 0} = 1; {n \brace 0} = {0 \brace k} = 0;\]</div>
<div class="math notranslate nohighlight">
\[{{n+1} \brace k} = j {n \brace k} + {n \brace {k-1}}\]</div>
<dl class="simple">
<dt>where <span class="math notranslate nohighlight">\(j\)</span> is:</dt><dd><p><span class="math notranslate nohighlight">\(n\)</span> for Stirling numbers of the first kind,
<span class="math notranslate nohighlight">\(-n\)</span> for signed Stirling numbers of the first kind,
<span class="math notranslate nohighlight">\(k\)</span> for Stirling numbers of the second kind.</p>
</dd>
</dl>
<p>The first kind of Stirling number counts the number of permutations of
<code class="docutils literal notranslate"><span class="pre">n</span></code> distinct items that have <code class="docutils literal notranslate"><span class="pre">k</span></code> cycles; the second kind counts the
ways in which <code class="docutils literal notranslate"><span class="pre">n</span></code> distinct items can be partitioned into <code class="docutils literal notranslate"><span class="pre">k</span></code> parts.
If <code class="docutils literal notranslate"><span class="pre">d</span></code> is given, the “reduced Stirling number of the second kind” is
returned: <span class="math notranslate nohighlight">\(S^{d}(n, k) = S(n - d + 1, k - d + 1)\)</span> with <span class="math notranslate nohighlight">\(n \ge k \ge d\)</span>.
(This counts the ways to partition <span class="math notranslate nohighlight">\(n\)</span> consecutive integers into <span class="math notranslate nohighlight">\(k\)</span>
groups with no pairwise difference less than <span class="math notranslate nohighlight">\(d\)</span>. See example below.)</p>
<p>To obtain the signed Stirling numbers of the first kind, use keyword
<code class="docutils literal notranslate"><span class="pre">signed=True</span></code>. Using this keyword automatically sets <code class="docutils literal notranslate"><span class="pre">kind</span></code> to 1.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.functions.combinatorial.numbers</span> <span class="kn">import</span> <span class="n">stirling</span><span class="p">,</span> <span class="n">bell</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.utilities.iterables</span> <span class="kn">import</span> <span class="n">multiset_partitions</span><span class="p">,</span> <span class="n">permutations</span>
</pre></div>
</div>
<p>First kind (unsigned by default):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">stirling</span><span class="p">(</span><span class="mi">6</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="n">kind</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">7</span><span class="p">)]</span>
<span class="go">[0, 120, 274, 225, 85, 15, 1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">perms</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">permutations</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">)))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="nb">sum</span><span class="p">(</span><span class="n">Permutation</span><span class="p">(</span><span class="n">p</span><span class="p">)</span><span class="o">.</span><span class="n">cycles</span> <span class="o">==</span> <span class="n">i</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">perms</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">)]</span>
<span class="go">[0, 6, 11, 6, 1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">stirling</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="n">kind</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">)]</span>
<span class="go">[0, 6, 11, 6, 1]</span>
</pre></div>
</div>
<p>First kind (signed):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">stirling</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="n">signed</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">)]</span>
<span class="go">[0, -6, 11, -6, 1]</span>
</pre></div>
</div>
<p>Second kind:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">stirling</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">12</span><span class="p">)]</span>
<span class="go">[0, 1, 511, 9330, 34105, 42525, 22827, 5880, 750, 45, 1, 0]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">sum</span><span class="p">(</span><span class="n">_</span><span class="p">)</span> <span class="o">==</span> <span class="n">bell</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">len</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">multiset_partitions</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">),</span> <span class="mi">2</span><span class="p">)))</span> <span class="o">==</span> <span class="n">stirling</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Reduced second kind:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">subsets</span><span class="p">,</span> <span class="n">oo</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">delta</span><span class="p">(</span><span class="n">p</span><span class="p">):</span>
<span class="gp">... </span>   <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">p</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="gp">... </span>       <span class="k">return</span> <span class="n">oo</span>
<span class="gp">... </span>   <span class="k">return</span> <span class="nb">min</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">i</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">i</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">subsets</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">parts</span> <span class="o">=</span> <span class="n">multiset_partitions</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">),</span> <span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="mi">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">sum</span><span class="p">(</span><span class="mi">1</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">parts</span> <span class="k">if</span> <span class="nb">all</span><span class="p">(</span><span class="n">delta</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="o">&gt;=</span> <span class="n">d</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">p</span><span class="p">))</span>
<span class="go">7</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">stirling</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">7</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="../utilities/iterables.html#sympy.utilities.iterables.multiset_partitions" title="sympy.utilities.iterables.multiset_partitions"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.utilities.iterables.multiset_partitions</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r219"><span class="brackets"><a class="fn-backref" href="#id39">R219</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Stirling_numbers_of_the_first_kind">https://en.wikipedia.org/wiki/Stirling_numbers_of_the_first_kind</a></p>
</dd>
<dt class="label" id="r220"><span class="brackets"><a class="fn-backref" href="#id40">R220</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Stirling_numbers_of_the_second_kind">https://en.wikipedia.org/wiki/Stirling_numbers_of_the_second_kind</a></p>
</dd>
</dl>
</dd></dl>

</section>
</section>
<section id="enumeration">
<h1>Enumeration<a class="headerlink" href="#enumeration" title="Permalink to this headline">¶</a></h1>
<p>Three functions are available. Each of them attempts to efficiently compute
a given combinatorial quantity for a given set or multiset which can be
entered as an integer, sequence or multiset (dictionary with
elements as keys and multiplicities as values). The <code class="docutils literal notranslate"><span class="pre">k</span></code> parameter indicates
the number of elements to pick (or the number of partitions to make). When
<code class="docutils literal notranslate"><span class="pre">k</span></code> is None, the sum of the enumeration for all <code class="docutils literal notranslate"><span class="pre">k</span></code> (from 0 through the
number of items represented by <code class="docutils literal notranslate"><span class="pre">n</span></code>) is returned. A <code class="docutils literal notranslate"><span class="pre">replacement</span></code> parameter
is recognized for combinations and permutations; this indicates that any item
may appear with multiplicity as high as the number of items in the original
set.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.functions.combinatorial.numbers</span> <span class="kn">import</span> <span class="n">nC</span><span class="p">,</span> <span class="n">nP</span><span class="p">,</span> <span class="n">nT</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">items</span> <span class="o">=</span> <span class="s1">&#39;baby&#39;</span>
</pre></div>
</div>
<section id="nc">
<h2>nC<a class="headerlink" href="#nc" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.functions.combinatorial.numbers.nC">
<span class="sig-prename descclassname"><span class="pre">sympy.functions.combinatorial.numbers.</span></span><span class="sig-name descname"><span class="pre">nC</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">replacement</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/functions/combinatorial/numbers.py#L1621-L1714"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.functions.combinatorial.numbers.nC" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the number of combinations of <code class="docutils literal notranslate"><span class="pre">n</span></code> items taken <code class="docutils literal notranslate"><span class="pre">k</span></code> at a time.</p>
<p>Possible values for <code class="docutils literal notranslate"><span class="pre">n</span></code>:</p>
<blockquote>
<div><p>integer - set of length <code class="docutils literal notranslate"><span class="pre">n</span></code></p>
<p>sequence - converted to a multiset internally</p>
<p>multiset - {element: multiplicity}</p>
</div></blockquote>
<p>If <code class="docutils literal notranslate"><span class="pre">k</span></code> is None then the total of all combinations of length 0
through the number of items represented in <code class="docutils literal notranslate"><span class="pre">n</span></code> will be returned.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">replacement</span></code> is True then a given item can appear more than once
in the <code class="docutils literal notranslate"><span class="pre">k</span></code> items. (For example, for ‘ab’ sets of 2 would include ‘aa’,
‘ab’, and ‘bb’.) The multiplicity of elements in <code class="docutils literal notranslate"><span class="pre">n</span></code> is ignored when
<code class="docutils literal notranslate"><span class="pre">replacement</span></code> is True but the total number of elements is considered
since no element can appear more times than the number of elements in
<code class="docutils literal notranslate"><span class="pre">n</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.functions.combinatorial.numbers</span> <span class="kn">import</span> <span class="n">nC</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.utilities.iterables</span> <span class="kn">import</span> <span class="n">multiset_combinations</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nC</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nC</span><span class="p">(</span><span class="s1">&#39;abc&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nC</span><span class="p">(</span><span class="s1">&#39;aab&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">2</span>
</pre></div>
</div>
<p>When <code class="docutils literal notranslate"><span class="pre">replacement</span></code> is True, each item can have multiplicity
equal to the length represented by <code class="docutils literal notranslate"><span class="pre">n</span></code>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">nC</span><span class="p">(</span><span class="s1">&#39;aabc&#39;</span><span class="p">,</span> <span class="n">replacement</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">35</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="nb">len</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">multiset_combinations</span><span class="p">(</span><span class="s1">&#39;aaaabbbbcccc&#39;</span><span class="p">,</span> <span class="n">i</span><span class="p">)))</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">)]</span>
<span class="go">[1, 3, 6, 10, 15]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">sum</span><span class="p">(</span><span class="n">_</span><span class="p">)</span>
<span class="go">35</span>
</pre></div>
</div>
<p>If there are <code class="docutils literal notranslate"><span class="pre">k</span></code> items with multiplicities <code class="docutils literal notranslate"><span class="pre">m_1,</span> <span class="pre">m_2,</span> <span class="pre">...,</span> <span class="pre">m_k</span></code>
then the total of all combinations of length 0 through <code class="docutils literal notranslate"><span class="pre">k</span></code> is the
product, <code class="docutils literal notranslate"><span class="pre">(m_1</span> <span class="pre">+</span> <span class="pre">1)*(m_2</span> <span class="pre">+</span> <span class="pre">1)*...*(m_k</span> <span class="pre">+</span> <span class="pre">1)</span></code>. When the multiplicity
of each item is 1 (i.e., k unique items) then there are 2**k
combinations. For example, if there are 4 unique items, the total number
of combinations is 16:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">sum</span><span class="p">(</span><span class="n">nC</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">))</span>
<span class="go">16</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="../utilities/iterables.html#sympy.utilities.iterables.multiset_combinations" title="sympy.utilities.iterables.multiset_combinations"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.utilities.iterables.multiset_combinations</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r221"><span class="brackets"><a class="fn-backref" href="#id41">R221</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Combination">https://en.wikipedia.org/wiki/Combination</a></p>
</dd>
<dt class="label" id="r222"><span class="brackets"><a class="fn-backref" href="#id42">R222</a></span></dt>
<dd><p><a class="reference external" href="http://tinyurl.com/cep849r">http://tinyurl.com/cep849r</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="np">
<h2>nP<a class="headerlink" href="#np" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.functions.combinatorial.numbers.nP">
<span class="sig-prename descclassname"><span class="pre">sympy.functions.combinatorial.numbers.</span></span><span class="sig-name descname"><span class="pre">nP</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">replacement</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/functions/combinatorial/numbers.py#L1447-L1510"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.functions.combinatorial.numbers.nP" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the number of permutations of <code class="docutils literal notranslate"><span class="pre">n</span></code> items taken <code class="docutils literal notranslate"><span class="pre">k</span></code> at a time.</p>
<p>Possible values for <code class="docutils literal notranslate"><span class="pre">n</span></code>:</p>
<blockquote>
<div><p>integer - set of length <code class="docutils literal notranslate"><span class="pre">n</span></code></p>
<p>sequence - converted to a multiset internally</p>
<p>multiset - {element: multiplicity}</p>
</div></blockquote>
<p>If <code class="docutils literal notranslate"><span class="pre">k</span></code> is None then the total of all permutations of length 0
through the number of items represented by <code class="docutils literal notranslate"><span class="pre">n</span></code> will be returned.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">replacement</span></code> is True then a given item can appear more than once
in the <code class="docutils literal notranslate"><span class="pre">k</span></code> items. (For example, for ‘ab’ permutations of 2 would
include ‘aa’, ‘ab’, ‘ba’ and ‘bb’.) The multiplicity of elements in
<code class="docutils literal notranslate"><span class="pre">n</span></code> is ignored when <code class="docutils literal notranslate"><span class="pre">replacement</span></code> is True but the total number
of elements is considered since no element can appear more times than
the number of elements in <code class="docutils literal notranslate"><span class="pre">n</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.functions.combinatorial.numbers</span> <span class="kn">import</span> <span class="n">nP</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.utilities.iterables</span> <span class="kn">import</span> <span class="n">multiset_permutations</span><span class="p">,</span> <span class="n">multiset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nP</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">6</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nP</span><span class="p">(</span><span class="s1">&#39;abc&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> <span class="o">==</span> <span class="n">nP</span><span class="p">(</span><span class="n">multiset</span><span class="p">(</span><span class="s1">&#39;abc&#39;</span><span class="p">),</span> <span class="mi">2</span><span class="p">)</span> <span class="o">==</span> <span class="mi">6</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nP</span><span class="p">(</span><span class="s1">&#39;aab&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nP</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">nP</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">)]</span>
<span class="go">[1, 3, 6, 6]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nP</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">==</span> <span class="nb">sum</span><span class="p">(</span><span class="n">_</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>When <code class="docutils literal notranslate"><span class="pre">replacement</span></code> is True, each item can have multiplicity
equal to the length represented by <code class="docutils literal notranslate"><span class="pre">n</span></code>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">nP</span><span class="p">(</span><span class="s1">&#39;aabc&#39;</span><span class="p">,</span> <span class="n">replacement</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">121</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="nb">len</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">multiset_permutations</span><span class="p">(</span><span class="s1">&#39;aaaabbbbcccc&#39;</span><span class="p">,</span> <span class="n">i</span><span class="p">)))</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">)]</span>
<span class="go">[1, 3, 9, 27, 81]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">sum</span><span class="p">(</span><span class="n">_</span><span class="p">)</span>
<span class="go">121</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="../utilities/iterables.html#sympy.utilities.iterables.multiset_permutations" title="sympy.utilities.iterables.multiset_permutations"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.utilities.iterables.multiset_permutations</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r223"><span class="brackets"><a class="fn-backref" href="#id43">R223</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Permutation">https://en.wikipedia.org/wiki/Permutation</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="nt">
<h2>nT<a class="headerlink" href="#nt" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.functions.combinatorial.numbers.nT">
<span class="sig-prename descclassname"><span class="pre">sympy.functions.combinatorial.numbers.</span></span><span class="sig-name descname"><span class="pre">nT</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/functions/combinatorial/numbers.py#L1925-L2045"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.functions.combinatorial.numbers.nT" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the number of <code class="docutils literal notranslate"><span class="pre">k</span></code>-sized partitions of <code class="docutils literal notranslate"><span class="pre">n</span></code> items.</p>
<p>Possible values for <code class="docutils literal notranslate"><span class="pre">n</span></code>:</p>
<blockquote>
<div><p>integer - <code class="docutils literal notranslate"><span class="pre">n</span></code> identical items</p>
<p>sequence - converted to a multiset internally</p>
<p>multiset - {element: multiplicity}</p>
</div></blockquote>
<p>Note: the convention for <code class="docutils literal notranslate"><span class="pre">nT</span></code> is different than that of <code class="docutils literal notranslate"><span class="pre">nC</span></code> and
<code class="docutils literal notranslate"><span class="pre">nP</span></code> in that
here an integer indicates <code class="docutils literal notranslate"><span class="pre">n</span></code> <em>identical</em> items instead of a set of
length <code class="docutils literal notranslate"><span class="pre">n</span></code>; this is in keeping with the <code class="docutils literal notranslate"><span class="pre">partitions</span></code> function which
treats its integer-<code class="docutils literal notranslate"><span class="pre">n</span></code> input like a list of <code class="docutils literal notranslate"><span class="pre">n</span></code> 1s. One can use
<code class="docutils literal notranslate"><span class="pre">range(n)</span></code> for <code class="docutils literal notranslate"><span class="pre">n</span></code> to indicate <code class="docutils literal notranslate"><span class="pre">n</span></code> distinct items.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">k</span></code> is None then the total number of ways to partition the elements
represented in <code class="docutils literal notranslate"><span class="pre">n</span></code> will be returned.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.functions.combinatorial.numbers</span> <span class="kn">import</span> <span class="n">nT</span>
</pre></div>
</div>
<p>Partitions of the given multiset:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">nT</span><span class="p">(</span><span class="s1">&#39;aabbc&#39;</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">7</span><span class="p">)]</span>
<span class="go">[1, 8, 11, 5, 1, 0]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nT</span><span class="p">(</span><span class="s1">&#39;aabbc&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="nb">sum</span><span class="p">(</span><span class="n">_</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">nT</span><span class="p">(</span><span class="s2">&quot;mississippi&quot;</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">12</span><span class="p">)]</span>
<span class="go">[1, 74, 609, 1521, 1768, 1224, 579, 197, 50, 9, 1]</span>
</pre></div>
</div>
<p>Partitions when all items are identical:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">nT</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">6</span><span class="p">)]</span>
<span class="go">[1, 2, 2, 1, 1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nT</span><span class="p">(</span><span class="s1">&#39;1&#39;</span><span class="o">*</span><span class="mi">5</span><span class="p">)</span> <span class="o">==</span> <span class="nb">sum</span><span class="p">(</span><span class="n">_</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>When all items are different:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">nT</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">),</span> <span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">6</span><span class="p">)]</span>
<span class="go">[1, 15, 25, 10, 1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nT</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">))</span> <span class="o">==</span> <span class="nb">sum</span><span class="p">(</span><span class="n">_</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Partitions of an integer expressed as a sum of positive integers:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.functions.combinatorial.numbers</span> <span class="kn">import</span> <span class="n">partition</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">partition</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
<span class="go">5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nT</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="n">nT</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="n">nT</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span> <span class="o">+</span> <span class="n">nT</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="go">5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nT</span><span class="p">(</span><span class="s1">&#39;1&#39;</span><span class="o">*</span><span class="mi">4</span><span class="p">)</span>
<span class="go">5</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="../utilities/iterables.html#sympy.utilities.iterables.partitions" title="sympy.utilities.iterables.partitions"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.utilities.iterables.partitions</span></code></a>, <a class="reference internal" href="../utilities/iterables.html#sympy.utilities.iterables.multiset_partitions" title="sympy.utilities.iterables.multiset_partitions"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.utilities.iterables.multiset_partitions</span></code></a>, <a class="reference internal" href="#sympy.functions.combinatorial.numbers.partition" title="sympy.functions.combinatorial.numbers.partition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.functions.combinatorial.numbers.partition</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r224"><span class="brackets"><a class="fn-backref" href="#id44">R224</a></span></dt>
<dd><p><a class="reference external" href="http://undergraduate.csse.uwa.edu.au/units/CITS7209/partition.pdf">http://undergraduate.csse.uwa.edu.au/units/CITS7209/partition.pdf</a></p>
</dd>
</dl>
</dd></dl>

</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h3><a href="../../index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Combinatorial</a><ul>
<li><a class="reference internal" href="#bell">bell</a></li>
<li><a class="reference internal" href="#bernoulli">bernoulli</a></li>
<li><a class="reference internal" href="#binomial">binomial</a></li>
<li><a class="reference internal" href="#catalan">catalan</a></li>
<li><a class="reference internal" href="#euler">euler</a></li>
<li><a class="reference internal" href="#factorial">factorial</a></li>
<li><a class="reference internal" href="#subfactorial">subfactorial</a></li>
<li><a class="reference internal" href="#factorial2-double-factorial">factorial2 / double factorial</a></li>
<li><a class="reference internal" href="#fallingfactorial">FallingFactorial</a></li>
<li><a class="reference internal" href="#fibonacci">fibonacci</a></li>
<li><a class="reference internal" href="#tribonacci">tribonacci</a></li>
<li><a class="reference internal" href="#harmonic">harmonic</a></li>
<li><a class="reference internal" href="#lucas">lucas</a></li>
<li><a class="reference internal" href="#genocchi">genocchi</a></li>
<li><a class="reference internal" href="#partition">partition</a></li>
<li><a class="reference internal" href="#multifactorial">MultiFactorial</a></li>
<li><a class="reference internal" href="#risingfactorial">RisingFactorial</a></li>
<li><a class="reference internal" href="#stirling">stirling</a></li>
</ul>
</li>
<li><a class="reference internal" href="#enumeration">Enumeration</a><ul>
<li><a class="reference internal" href="#nc">nC</a></li>
<li><a class="reference internal" href="#np">nP</a></li>
<li><a class="reference internal" href="#nt">nT</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="elementary.html"
                        title="previous chapter">Elementary</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="special.html"
                        title="next chapter">Special</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/modules/functions/combinatorial.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="special.html" title="Special"
             >next</a> |</li>
        <li class="right" >
          <a href="elementary.html" title="Elementary"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" >Functions</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Combinatorial</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/functions/combinatorial.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:28:19 GMT -->
</html>